# CMake Generate Executable File.
# Author: Livmee

set(TARGET_NAME fastExe)
# 源文件列表
set(SOURCES
    # ${CMAKE_CURRENT_SOURCE_DIR}/simpletest/main.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/fastcodding/main.cpp
    ${CMAKE_SOURCE_DIR}/res.qrc
)

set(HEADERS
    # ${CMAKE_CURRENT_SOURCE_DIR}/simpletest/main.h
    ${CMAKE_CURRENT_SOURCE_DIR}/fastcodding/main.h
)

# 添加可执行文件
add_executable(${TARGET_NAME}
    ${SOURCES}
    ${HEADERS}
)

# PUBLIC: 当前和关联目标构建时都可见
# PRIVATE: 仅当前目标构建时可见
# INTERFACE: 仅关联目标构建时可见
target_include_directories(${TARGET_NAME}
    PRIVATE
    ${CMAKE_SOURCE_DIR}/cpp/include
    ${CMAKE_CURRENT_SOURCE_DIR}/fastcodding/
)

# 只能链接静态库，动态库不允许链接(动态库直接被调用)
target_link_libraries(${TARGET_NAME} PRIVATE fastLib yaml-cpp)
target_link_libraries(${TARGET_NAME}
    PRIVATE
    Qt6::Widgets
    Qt6::Gui
    Qt6::Core
    Qt6::SerialPort
)

install(TARGETS ${TARGET_NAME}
    # EXPORT MyLibTargets
    LIBRARY DESTINATION ${PROJECT_NAME}/lib
    ARCHIVE DESTINATION ${PROJECT_NAME}/lib
    RUNTIME DESTINATION ${PROJECT_NAME}/bin
)

# 设置相对路径(相对于可执行文件), 用于寻找动态链接库(仅 UNIX 或 类-UNIX 系统)
# 对与 WIN, 推荐将 DLL 直接复制到 bin(与 exe 同级)
# if(UNIX)
#     set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
# endif()

# 生成对象安装
# 用于 XXXConfig.cmake 的导出
# 配置安装位置，可执行文件 .exe
install(TARGETS ${TARGET_NAME}
    # EXPORT MyLibTargets
    RUNTIME DESTINATION ${PROJECT_NAME}/bin
)

# 头目录文件安装
# 配置安装位置，头文件.h
# 安装文件匹配
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
    DESTINATION ${PROJECT_NAME}/
    FILES_MATCHING PATTERN "*.h"      
)